package liu.zhi.peng;

public class Student implements Comparable {
    public String name;
    public String id;
    public double Chinese;
    public double Math;
    public double English;
    public Student(String name,String id,double Chinese,double Math,double English){
        this.name=name;
        this.id=id;
        this.Chinese = Chinese;
        this.Math = Math;
        this.English = English;
    }

    @Override
    public String toString() {
        return  name  +","+
                id  +","+
                 Chinese +","+
               Math +","+
                English;
    }

    @Override
    public int compareTo(Object o) {
        if(o instanceof Student){
            Student stu = (Student)o;
            if((this.English+this.Chinese+this.Math)>(stu.Chinese+stu.Math+stu.English))
                return -1;
            else if((this.English+this.Chinese+this.Math)<(stu.Chinese+stu.Math+stu.English))
                return 1;
            else if(this.Chinese>stu.Chinese)
                return -1;
            else if(this.Chinese< stu.Chinese)
                return 1;
            else if(this.Math>stu.Math)
                return -1;
            else if(this.Math< stu.Math)
                return 1;
            else if(this.English>stu.English)
                return -1;
            else if(this.English< stu.English)
                return 1;
            else
                return this.id.compareTo(stu.id);
        }
        return -1;//如果比较的对象不是student对象时返回-1
    }
}
